<!-- PAGE CONTENT WRAPPER -->
<div class="page-content-wrap">
    <div class="row">
        <div class="col-md-12">
            <form class="form-horizontal">
                <div class="panel panel-default">
                    <input name="go" value="${param.go}" type="hidden">
                    <div class="panel-heading">
                        <h3 class="panel-title" id="title"></h3>
                        <ul class="panel-controls">
                            <li><a href="javascript:window.location.href=document.referrer;"><i
                                    class="fa fa-arrow-left"></i></a></li>
                        </ul>
                    </div>
                    <div class="panel-body">
                        <p>在这里新增或者修改一个调查问卷。</p>
                    </div>
                    <input type="hidden" id="questionnaireId" value="${questionnaire.id}">

                    <div class="panel-body">
                        <div class="row">
                            <div class="col-md-9">
                                <div class="form-group">
                                    <label class="col-md-3 control-label">问卷名称</label>

                                    <div class="col-md-9">
                                        <div class="input-group">
                                            <span class="input-group-addon"><span class="fa fa-pencil"></span></span>
                                            <input type="text" class="form-control" id="name"
                                                   value="${questionnaire.name}"/>
                                        </div>
                                        <div id="nameValid"></div>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-md-3 control-label">预定时间</label>
                                    <div class="col-md-8">
                                        <div class="input-group">
                                            <span class="input-group-addon"><span
                                                    class="glyphicon glyphicon-calendar"></span></span>
                                            <input class="form-control datepicker" id="publishTime"
                                                   value="${questionnaire.publishTime}">
                                        </div>
                                        <div id="publishTimeValid"></div>
                                    </div>
                                    <%--<div class="col-md-4">
                                        <div class="input-group">
                                            <span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span>
                                            <input class="form-control timepicker24" id="publishTime" data-time="1466057884000">
                                        </div>
                                    </div>--%>
                                </div>
                                <div class="form-group">
                                    <label class="col-md-3 control-label">至</label>
                                    <div class="col-md-8">
                                        <div class="input-group">
                                            <span class="input-group-addon"><span
                                                    class="glyphicon glyphicon-calendar"></span></span>
                                            <input class="form-control datepicker" id="endTime"
                                                   value="${questionnaire.endTime}">
                                        </div>
                                        <div id="endTimeValid"></div>
                                    </div>
                                    <%--<div class="col-md-4">
                                        <div class="input-group">
                                            <span class="input-group-addon"><span class="glyphicon glyphicon-time"></span></span>
                                            <input class="form-control timepicker24" id="eTime" data-time="1468166100000">
                                        </div>
                                    </div>--%>
                                </div>
                                <div class="form-group">
                                    <label class="col-md-3 control-label">选择问题表单</label>
                                    <div class="col-md-9">
                                        <select class="form-control select" id="formId">
                                            <option value="" >无</option>
                                            <c:forEach var="par" items="${questionFormRepository.findAll()}">
                                                <option value="${par.id}"
                                                        <c:if test="${questionnaire.formId==par.id}">selected</c:if>>${par.name}</option>
                                            </c:forEach>
                                        </select>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="panel-footer">
                            <span class="btn btn-primary pull-right" onclick="submita()">保存</span>
                        </div>
                    </div>
                </div>
            </form>

        </div>
    </div>

</div>
<!-- END PAGE CONTENT WRAPPER -->
<script>
    var questionnaireId;
    function submita() {
        var param = {};
        param.id = questionnaireId == '' ? -1 : questionnaireId;
        param.name = $('#name').val();
        param.publishTime = $('#publishTime').val();
        param.endTime = $('#endTime').val();
        param.formId = $('#formId').val();
        if (!param.name || param.name == '') {
            var vhtml = '<label id="re-password-error" class="error" for="re-password">请输入问卷名称！</label>';
            $('#nameValid').html(vhtml);
            return false;
        }
        if (!param.publishTime || param.publishTime == '') {
            var vhtml = '<label id="re-password-error" class="error" for="re-password">请选择预定开始时间！</label>';
            $('#publishTimeValid').html(vhtml);
            return false;
        }
        if (!param.endTime || param.endTime == '') {
            var vhtml = '<label id="re-password-error" class="error" for="re-password">请选择预定结束时间！</label>';
            $('#endTimeValid').html(vhtml);
            return false;
        }

        json("/admin/option/saveQuestionnaire.jspa", {param: JSON.stringify(param)}, function (data) {
            window.location.href = document.referrer;
        });
    }
    function submitb() {
        setTimeout(function () {
            submita();
        }, 100);
    }

    $(function () {
        questionnaireId = $('#questionnaireId').val();
        $('#title').html(questionnaireId == '' ? '添加问卷' : '修改问卷');
    });
</script>
